﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="NewService.aspx.cs" Inherits="MonkeyWarranty.Web.InstantTickets.NewService" %>

<%@ Import Namespace="Resources" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    <title>
        <%=GlobalStrings.InstantTicketForm %> - <%=GlobalStrings.Services %></title>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h2><%=GlobalStrings.InstantTicketForm %>: <%=GlobalStrings.Services%></h2>
    <p></p>
    <span class="failureNotification">
        <asp:Literal ID="lblErrorMessage" runat="server"></asp:Literal></span>
    <div style="min-width: 960px;">
        <fieldset class="register">
            <div style="float: left; margin-right: 50px;">
                <p>
                    <asp:HiddenField ID="hidServiceId" runat="server" />
                    <label><%=GlobalStrings.Services%></label>
                    <asp:TextBox ID="txtServiceName" runat="server" ReadOnly="True" CssClass="textEntry name"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtServiceName"
                        CssClass="failureNotification" ValidationGroup="AddNew">(*)</asp:RequiredFieldValidator>
                    <a href="javascript:void(0);" onclick="javascript:SelectService();">Select</a>
                </p>

                <p>
                    <label><%=GlobalStrings.Quantity %></label><asp:TextBox ID="txtQuantity" runat="server" CssClass="textEntry codeprefix" Text="1"></asp:TextBox>
                </p>
                <p>
                    <label><%=GlobalStrings.ServiceType %></label><asp:DropDownList ID="ddlServiceTypes" runat="server"></asp:DropDownList>
                </p>
                <p>
                    <label><%=GlobalStrings.ErrorCode %></label><asp:DropDownList ID="ddlErrors" runat="server"></asp:DropDownList>
                </p>
            </div>

            <div style="float: left;">
                <p>
                    <label><%=GlobalStrings.Description %></label><asp:TextBox ID="txtDescription" runat="server" TextMode="MultiLine" CssClass="textEntry description"></asp:TextBox>
                </p>
                <p>
                    <label><%=GlobalStrings.Note %></label><asp:TextBox ID="txtNote" TextMode="MultiLine" runat="server" CssClass="textEntry description"></asp:TextBox>
                </p>
            </div>
        </fieldset>
    </div>

    <p></p>
    <div>
        <input id="btnCancel" type="button" value="<%=GlobalStrings.Cancel %>"
            class="submitButton" onclick="javascript:window.location='Edit.aspx?id=<%=Request.Params["ticketId"] %>#tabs-1';" />
        <asp:Button ID="btnSave" runat="server" Text="<%$ Resources:GlobalStrings, Save %>"
            CssClass="submitButton" ValidationGroup="AddNew" OnClick="btnSave_Click" />
    </div>

    <div id="services-dialog-form" title="<%=GlobalStrings.ServicesList %>">
        <div class="filtering">
            <label>
                <%=GlobalStrings.Name %>:
                <input type="text" name="name" id="name" /></label>
            <button type="submit" id="LoadRecordsButton"><%=GlobalStrings.LoadRecords %></button>
        </div>
        <div id="ServicesTableContainer"></div>
        <p><a href="../Services/New.aspx" target="_blank"><%=GlobalStrings.AddNew %></a></p>
    </div>

    <script type="text/javascript">
        $(document).ready(function() {
            $("#<%=txtServiceName.ClientID %>").prop("disabled", true);

            $("#dialog:ui-dialog").dialog("destroy");
            $("#services-dialog-form").dialog({
                autoOpen: false,
                height: 400,
                width: 800,
                modal: true
            });

            //Prepare jtable plugin
            $('#ServicesTableContainer').jtable({
                paging: true,
                pageSize: 10,
                sorting: true,
                defaultSorting: 'Code ASC',
                actions: {
                    listAction: '../Services/List.aspx/ServiceList'
                },
                fields: {
                    Id: {
                        key: true,
                        create: false,
                        edit: false,
                        list: false
                    },
                    Code: {
                        title: '<%=GlobalStrings.Code %>'
                    },
                    Name: {
                        title: '<%=GlobalStrings.Name %>',
                        width: '20%',
                        display: function (data) {
                            return '<a href="javascript:void(0);" onclick="javascript:ServiceSelect({Id:' + data.record.Id +
                            ',Code:\'' + data.record.Code + '\'' +
                                ',Name:\'' + data.record.Name + '\'' +
                                    '});">' + data.record.Name + '</a>';
                        }
                    }
                }
            });
            
            $('#LoadRecordsButton').click(function (e) {
                e.preventDefault();
                $('#ServicesTableContainer').jtable('load', {
                    name: $('#name').val()
                });
            });
        });
    </script>

    <script type="text/javascript">
        function ServiceSelect(service) {
            $("#services-dialog-form").dialog("close");
            $("#<%=hidServiceId.ClientID %>").val(service.Id);
            $("#<%=txtServiceName.ClientID %>").val(service.Name);
        }

        function SelectService() {
            // load data
            $("#services-dialog-form").dialog("open");
            $('#ServicesTableContainer').jtable('load',{name: $('#name').val()});
        }
    </script>
</asp:Content>
